package com.tpshion.cloud.auth.domain.dto;

import com.tpshion.cloud.common.support.Constants;
import org.springframework.util.StringUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * 登录数据
 */
@Valid
public class LoginDto {

    @Size(max = 20,message = "账号长度不能超过20")
    @Pattern(regexp = Constants.ACCOUNT_REGEXP, message = "账号格式不合法，仅支持字母，数字，下划线")
    private String account;

    @Pattern(regexp = Constants.PHONE_REGEXP, message = "手机号不正确")
    private String phone;

    @Pattern(regexp = Constants.EMAIL_REGEXP, message = "邮箱不正确")
    private String email;

    @NotEmpty(message = "密码不能为空")
    @Size(min = 5,max = 20, message = "密码长度5-20位")
    @Pattern(regexp = Constants.PASSWORD_REGEXP, message = "密码格式不合法，仅支持字母，数字，下划线")
    private String password;

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "LoginDto{" +
                "account='" + account + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    /**
     * 去除输入空格
     */
    public void init(){
        this.account = StringUtils.isEmpty(this.account) ? this.account : this.account.trim();
        this.email = StringUtils.isEmpty(this.email) ? this.email : this.email.trim();
        this.phone = StringUtils.isEmpty(this.phone) ? this.phone : this.phone.trim();
        this.password = StringUtils.isEmpty(this.password) ? this.password : this.password.trim();
    }
}
